//
//  CXRecommendTableViewCell.m
//  Delicious
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "CXRecommendTableViewCell.h"
#import "Masonry.h"
#import "CXRecommendModel.h"
#import "UIImageView+WebCache.h"

@interface CXRecommendTableViewCell ()

@property (nonatomic, retain) UIScrollView *scroll;
@property (nonatomic, retain) UILabel *label_title;
@property (nonatomic, retain) UIImageView *img1;
@property (nonatomic, retain) UILabel *label1;
@property (nonatomic, retain) UILabel *label1_1;
@property (nonatomic, retain) UIImageView *img2;
@property (nonatomic, retain) UILabel *label2;
@property (nonatomic, retain) UILabel *label2_1;
@property (nonatomic, retain) UIImageView *img3;
@property (nonatomic, retain) UILabel *label3;
@property (nonatomic, retain) UILabel *label3_1;

@end

@implementation CXRecommendTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.scroll = [[UIScrollView alloc] init];
        //self.scroll.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:self.scroll];
        
        self.label_title = [[UILabel alloc] init];
        //self.label_title.backgroundColor = [UIColor greenColor];
        [self.scroll addSubview:self.label_title];
        
        self.img1 = [[UIImageView alloc] init];
        //self.img1.backgroundColor = [UIColor redColor];
        [self.scroll addSubview:self.img1];
        
        self.img2 = [[UIImageView alloc] init];
        //self.img2.backgroundColor = [UIColor redColor];
        [self.scroll addSubview:self.img2];
        
        self.img3 = [[UIImageView alloc] init];
        //self.img3.backgroundColor = [UIColor redColor];
        [self.scroll addSubview:self.img3];
        
        self.label1 = [[UILabel alloc] init];
        //self.label1.backgroundColor = [UIColor blueColor];
        self.label1.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.label1];
        
        self.label2 = [[UILabel alloc] init];
        //self.label2.backgroundColor = [UIColor blueColor];
        self.label2.textAlignment = NSTextAlignmentCenter;

        [self.contentView addSubview:self.label2];
        
        self.label3 = [[UILabel alloc] init];
        //self.label3.backgroundColor = [UIColor blueColor];
        self.label3.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.label3];
        
        self.label1_1 = [[UILabel alloc] init];
        //self.label1_1.backgroundColor = [UIColor blueColor];
        self.label1_1.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.label1_1];
        
        self.label2_1 = [[UILabel alloc] init];
        //self.label2_1.backgroundColor = [UIColor blueColor];
        self.label2_1.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.label2_1];
        
        self.label3_1 = [[UILabel alloc] init];
        //self.label3_1.backgroundColor = [UIColor blueColor];
        self.label3_1.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.label3_1];
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.scroll.frame = self.contentView.frame;
    self.scroll.contentSize = CGSizeMake(WIDTH * 2, self.scroll.frame.size.height);
    //NSLog(@"%@", NSStringFromCGRect(self.contentView.frame));
    
    [self.label_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView);
        make.top.mas_equalTo(self.contentView).offset(5);
        make.height.mas_equalTo(@30);
    }];
    
    [self.img1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).offset(30);
        make.top.mas_equalTo(self.label_title.mas_bottom).offset(10);
        make.right.mas_equalTo(self.img2.mas_left).offset(-20);
        make.height.mas_equalTo(self.img1.mas_width);
    }];
    self.img1.layer.cornerRadius = self.img1.frame.size.width / 2;
    self.img1.clipsToBounds = YES;
    
    [self.img2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.img1.mas_right).offset(20);
        make.top.mas_equalTo(self.img1);
        make.right.mas_equalTo(self.img3.mas_left).offset(-20);
        make.height.mas_equalTo(self.img1.mas_height);
        make.width.mas_equalTo(self.img1);
    }];
    self.img2.layer.cornerRadius = self.img2.frame.size.width / 2;
    self.img2.clipsToBounds = YES;
    
    [self.img3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.img2.mas_right).offset(20);
        make.top.mas_equalTo(self.img2);
        make.right.mas_equalTo(self.contentView).offset(-30);
        make.height.mas_equalTo(self.img1.mas_height);
        make.width.mas_equalTo(self.img1);
    }];
    self.img3.layer.cornerRadius = self.img3.frame.size.width / 2;
    self.img3.clipsToBounds = YES;
    
    [self.label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.img1);
        make.top.mas_equalTo(self.img1.mas_bottom).offset(10);
        make.width.mas_equalTo(self.img1);
        make.height.mas_equalTo(@30);
    }];
    
    [self.label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.img2);
        make.top.mas_equalTo(self.img2.mas_bottom).offset(10);
        make.width.mas_equalTo(self.label1);
        make.height.mas_equalTo(self.label1);
    }];
    
    [self.label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.img3);
        make.top.mas_equalTo(self.img3.mas_bottom).offset(10);
        make.width.mas_equalTo(self.label1);
        make.height.mas_equalTo(self.label1);
    }];
    
    [self.label1_1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.img1);
        make.top.mas_equalTo(self.label1.mas_bottom).offset(10);
        make.width.mas_equalTo(self.img1);
        make.height.mas_equalTo(@30);
    }];
    
    [self.label2_1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.img2);
        make.top.mas_equalTo(self.label2.mas_bottom).offset(10);
        make.width.mas_equalTo(self.label2);
        make.height.mas_equalTo(self.label2);
    }];
    
    [self.label3_1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.img3);
        make.top.mas_equalTo(self.label3.mas_bottom).offset(10);
        make.width.mas_equalTo(self.label3);
        make.height.mas_equalTo(self.label3);
    }];
    
    //self.scroll.contentSize = CGSizeMake(WIDTH, self.label3_1.frame.origin.y + self.label3_1.frame.size.height + 10);
    
}

- (void)setModel_today:(CXRecommendModel *)model_today
{
    if (_model_today != model_today) {
        _model_today = model_today;
    }
    self.label_title.text = self.model_today.title;

//    
//    [self.img1 sd_setImageWithURL:[NSURL URLWithString:self.model_today.obj[0][@"image"]] placeholderImage:[UIImage imageNamed:@""]];
//    self.label1.text = self.model_today.obj[0][@"title"];
//    self.label1_1.text = self.model_today.obj[0][@"gongxiao"];
////    [self.img2 sd_setImageWithURL:[NSURL URLWithString:self.model_today.obj[1][@"image"]] placeholderImage:[UIImage imageNamed:@""]];
////    self.label2.text = self.model_today.obj[1][@"title"];

    
    [self.img1 sd_setImageWithURL:[NSURL URLWithString:self.model_today.obj[0][@"image"]] placeholderImage:[UIImage imageNamed:@""]];
    self.label1.text = self.model_today.obj[0][@"title"];
    self.label1_1.text = self.model_today.obj[0][@"gongxiao"];
//    [self.img2 sd_setImageWithURL:[NSURL URLWithString:self.model_today.obj[1][@"image"]] placeholderImage:[UIImage imageNamed:@""]];
//    self.label2.text = self.model_today.obj[1][@"title"];
//    self.label2_1.text = self.model_today.obj[1][@"gongxiao"];
//    [self.img3 sd_setImageWithURL:[NSURL URLWithString:self.model_today.obj[2][@"image"]] placeholderImage:[UIImage imageNamed:@""]];
//    self.label3.text = self.model_today.obj[2][@"title"];
//    self.label3_1.text = self.model_today.obj[2][@"gongxiao"];
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
